//$Id: Player.java 180 2010-11-07 00:12:45Z cr.carbon $

package builders;
import java.util.ArrayList;

/**
 * This Player class defines a Player object, and is instantiated by Logic class only.
 * @author Liang Yujing
 *
 */
public class Player {
	private String name;	
	private Piece myPiece;
	private int homebase;
	private int pointsAccumulated;
	
	public enum Resource{
		CEMENT, BRICK, MUD, GLASS, DUNG, SAND;
	}

	/*
	 * indexes for currentResourceslist:
	 * index 0 == cement; 
	 * index 1 == brick; 
	 * index 2 == mud; 
	 * index 3 == glass; 
	 * index 4 == dung, 
	 * index 5 == sand
	 * 
	 * visibility of currentResourcesList changed to protected to accomodate changes in AI
	 * for UnitTestingAI and aiTestCase
	 */
	protected int[] currentResourcesList = new int[6];
	private ArrayList<Building> buildingsOwned = new ArrayList<Building>();
	
	/**
	 * change can be positive or negative
	 * @param change
	 */
	private void changePointsAccumulated(int change){
		pointsAccumulated = pointsAccumulated + change;
	}

	/**
	 * creates a Player with a Piece attached to it
	 * @param name
	 * @param homebase
	 */
	public Player(String name, int homebase){
		this.name = name;
		this.homebase = homebase;
		createNewPiece();
	}
	
	/**
	 * creates a Piece and sets its position to player's homebase
	 */
	public void createNewPiece(){
		myPiece = new Piece(getHomeBase());
		myPiece.setPosition(this.getHomeBase());
	}
	
	public String getPieceFileName(){
		return myPiece.getPieceFileName();
	}

	public String getName(){
		return name;
	}	

	public int getPiecePosition(){
		return myPiece.getPosition();
	}

	public int getHomeBase() {
		return homebase;
	}	
	
	public int getPointsAccumulated(){
		return pointsAccumulated;
	}

	public int getCurrentResourceAmount(Resource r){
		return currentResourcesList[r.ordinal()];
	}

	public void setCurrentResourceAmount(Resource r, int amount){
		currentResourcesList[r.ordinal()] = amount;
	}
	
	public int[] getCurrentResourcesList(){
		return currentResourcesList;
	}

	public int throwDie(){
		return Die.throwDie();
	}

	public void changePiecePosition(int newPosition) {
		myPiece.setPosition(newPosition);
	}

	public void addBuilding(Building b){
		buildingsOwned.add(b);
		changePointsAccumulated(b.getPoints());
	}
	
	public ArrayList<Building> getBuildingsOwned(){
		return buildingsOwned;
	}
	
}

